package com.lh.music;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.view.View;
import android.widget.Toast;

import com.lh.music.activity.BaseActivity;
import com.lh.music.dao.SongDao;
import com.lh.music.fragment.MainFragment;

import java.sql.SQLException;

public class MainActivity extends BaseActivity implements MainFragment.OnMainFragmentClickListener{
    private SongDao dao;
    private MainFragment mainFragment;
    private DrawerLayout drawerLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        dao=new SongDao(this);
        drawerLayout= (DrawerLayout) findViewById(R.id.drawerLayout);
        initFragment();
        //加载退出前的播放歌曲
        try {
            app.currentSong=dao.findNowPlaySong();
            Toast.makeText(app, "上次播放列表的长度"+dao.findPlaySongList().size(), Toast.LENGTH_SHORT).show();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }



    private void initFragment() {
        mainFragment=new MainFragment();
        FragmentTransaction ft=getSupportFragmentManager().beginTransaction();
        ft.add(R.id.container,mainFragment)
                .commit();
        mainFragment.setOnMainFragmentClickListener(this);
    }


    @Override
    public void showMenuClick() {
        View left=findViewById(R.id.left);
        drawerLayout.openDrawer(left);
    }
}
